from django.urls import re_path
from rest_framework.urls import path
from . import views

urlpatterns = [
    # 基本是图类 APIView
    path("book/",views.BookViewSerializer.as_view()),
    re_path("^bookinfo/(?P<id>\d+)/$",views.BookInfoViewserializer.as_view()),  # 正则表达式的  path

    # 通用视图类 GenericAPIView
    path('book2/',views.Book2ViewSerializer.as_view()),
    re_path("^bookinfo2/(?P<pk>\d+)/$",views.BookInfo2ViewSerializer.as_view()),

    # 扩展视图 Mixins + GenericAPIView
    path("book3/",views.BookMixinSerializer.as_view()),
    re_path("^bookinfo3/(?P<pk>\d+)/$",views.BookInfoMixinSerializer.as_view()),

    # 9个子类视图
    path("book4/", views.BookModelView.as_view()),
    re_path("^bookinfo4/(?P<pk>\d+)/$",views.BookInfoModelView.as_view()),



    # 视图集 ViewSet 基本视图集
    path("book5/", views.BookViewSet.as_view({
        "get": "book_list",
        'post': "book_create",
    })),
    re_path('^bookinfo5/(?P<pk>\d+)/$',views.BookViewSet.as_view({
        "get": "book_listinfo",
        "put": "book_update",
        "delete": "book_delete",
    })),


    # 视图集 GenericViewSet 通用视图集
    path("book6/", views.BookGenericViewSet.as_view({
        "get": "list",
        'post': "create",
    })),
    re_path('^bookinfo6/(?P<pk>\d+)/$',views.BookGenericViewSet.as_view({
        "get": "listinfo",
        "put": "update",
        "delete": "delete",
    })),

    # 视图集 GenericViewSet + Mixins 混入类
    path('book7/',views.BookGenericViewSetMixin.as_view({
        "get":"list",
        "post":"create",
    })),
    re_path("^bookinfo7/(?P<pk>\d+)/$",views.BookGenericViewSetMixin.as_view(
        {
            "get": "retrieve",
            "put": "update",
            "delete": "destroy",
         }
    )),

    # 视图集 ReadOnlyModelViewSet + Mixins 混入类
    path("book8/",views.BookReadOnlyModelViewSet.as_view({
        "get":"list",
        "post":"create",
    })),
    re_path("bookinfo8/(?P<pk>\d+)/$",views.BookReadOnlyModelViewSet.as_view({
        "get":"retrieve",
        "put":"update",
        "delete":"destroy",
    })),

    # 视图集 ModelViewSet 模型视图集
    path("book9/",views.BookModelViewSet.as_view({
        "get":"list",
        "post":"create",
    })),
    re_path("bookinfo9/(?P<pk>\d+)/$",views.BookModelViewSet.as_view({
        "get":"retrieve",
        "put":"update",
        "delete":"destroy",
    })),
]


""" 路由集 Routers """
from rest_framework.routers import DefaultRouter,SimpleRouter
# 1. 实例化 路由类
router = SimpleRouter()
# 2. 给路由注册视图集
router.register('book10',views.BookModelViewSet,basename="book10")

# 3. 把生成的路由列表 和 urlpatterns进行拼接
urlpatterns += router.urls